package com.cs4261.smartalarm.backend;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {
	//database name and version
	private static final String DATABASE_NAME = "smartalarm.db";
	private static final int DATABASE_VERSION = 1;
	
	//alarms table
	public static final String TABLE_ALARMS = "alarms";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NAME = "_name";
	
	//locations table
	public static final String TABLE_LOCATIONS = "locations";
	//public static final String COLUMN_ID = "_id";
	//public static final String COLUMN_NAME = "_name";
	public static final String COLUMN_ADDRESS = "_address";
	
	//other tables?

	//Table creation sql statements
	private static final String CREATE_ALARMS = "create table "
			+ TABLE_ALARMS + "(" + COLUMN_ID
			+ " integer primary key autoincrement, " + COLUMN_NAME
			+ " text not null);";
	private static final String CREATE_LOCATIONS = "create table "
			+ TABLE_LOCATIONS + "(" + COLUMN_ID
			+ " integer primary key autoincrement, " + COLUMN_NAME
			+ " text not null," + COLUMN_ADDRESS
			+ " text not null);";
	

	public MySQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		Log.d("MySQLiteHelper", "Finishing constructor");
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_ALARMS);
		db.execSQL(CREATE_LOCATIONS);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(MySQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALARMS);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOCATIONS);
		onCreate(db);
	}

}